package com.hlj.ncp.warehouse.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.hlj.ncp.common.core.domain.AjaxResult;
import com.hlj.ncp.warehouse.entity.ColdStorageThreshold;
import com.hlj.ncp.warehouse.service.IColdStorageThresholdService;

import java.util.List;

/**
 * 冷库温湿度阈值设置 控制器
 */
@Controller
@RequestMapping("/warehouse/coldStorageThreshold")
public class ColdStorageThresholdController {
    
    @Autowired
    private IColdStorageThresholdService coldStorageThresholdService;

    /**
     * 冷库温湿度阈值设置页面
     */
    @GetMapping("/index")
    public String index() {
        return "warehouse/coldStorageThreshold/index";
    }

    /**
     * 查询冷库温湿度阈值设置列表
     */
    @GetMapping("/list")
    @ResponseBody
    public AjaxResult list(ColdStorageThreshold coldStorageThreshold) {
        List<ColdStorageThreshold> list = coldStorageThresholdService.selectColdStorageThresholdList(coldStorageThreshold);
        return AjaxResult.success(list);
    }

    /**
     * 获取冷库温湿度阈值设置详细信息
     */
    @GetMapping(value = "/{thresholdId}")
    @ResponseBody
    public AjaxResult getInfo(@PathVariable("thresholdId") Long thresholdId) {
        return AjaxResult.success(coldStorageThresholdService.selectColdStorageThresholdById(thresholdId));
    }
    
    /**
     * 根据仓库ID和区域查询阈值设置
     */
    @GetMapping(value = "/getByWarehouseAndArea")
    @ResponseBody
    public AjaxResult getByWarehouseAndArea(@RequestParam("warehouseId") Long warehouseId, @RequestParam("storageArea") String storageArea) {
        return AjaxResult.success(coldStorageThresholdService.selectThresholdByWarehouseAndArea(warehouseId, storageArea));
    }

    /**
     * 新增冷库温湿度阈值设置
     */
    @PostMapping
    @ResponseBody
    public AjaxResult add(@RequestBody ColdStorageThreshold coldStorageThreshold) {
        return AjaxResult.success(coldStorageThresholdService.insertColdStorageThreshold(coldStorageThreshold));
    }

    /**
     * 修改冷库温湿度阈值设置
     */
    @PutMapping
    @ResponseBody
    public AjaxResult edit(@RequestBody ColdStorageThreshold coldStorageThreshold) {
        return AjaxResult.success(coldStorageThresholdService.updateColdStorageThreshold(coldStorageThreshold));
    }

    /**
     * 删除冷库温湿度阈值设置
     */
    @DeleteMapping("/{thresholdIds}")
    @ResponseBody
    public AjaxResult remove(@PathVariable Long[] thresholdIds) {
        return AjaxResult.success(coldStorageThresholdService.deleteColdStorageThresholdByIds(thresholdIds));
    }
} 